package cc.lj.internal.coupons.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.core.model.PageParam;
import cc.lj.internal.coupons.domain.ticket.repository.ITicketBatchMerchantListRepository;
import cc.lj.internal.coupons.infrastructure.dao.ITicketBatchMerchantListMapper;
import cc.lj.internal.coupons.infrastructure.excepion.CoupousExceptionEnum;
import cc.lj.internal.coupons.infrastructure.po.TicketBatchMerchantListPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * 电子券商户黑白名单表　mysql仓储实现
 * @author liangxifeng
 * @date 2023-06-26
 */
@Repository("ticketBatchMerchantListMysqlRespository")
public class TicketBatchMerchantListMysqlRespository implements ITicketBatchMerchantListRepository,BasePageHelper<TicketBatchMerchantListPO> {
    @Autowired
    private ITicketBatchMerchantListMapper mapper;
    @Override
    public List<TicketBatchMerchantListPO> list(TicketBatchMerchantListPO entityPO) {
        QueryWrapper<TicketBatchMerchantListPO> wrapper = new QueryWrapper<>(entityPO);
        List<TicketBatchMerchantListPO> entitys = mapper.selectList(wrapper);
        return entitys;
    }

    @Override
    public Integer updateById(TicketBatchMerchantListPO entityPO) {
        Integer res = mapper.updateById(entityPO);
        if (res != 1)
        {
            throw new ServiceException(CoupousExceptionEnum.UPDATE_TICKET_BATCH_MERCHANT_FAILED);
        }
        return res;
    }

    @Override
    public TicketBatchMerchantListPO getById(Integer id) {
        TicketBatchMerchantListPO entityPO =  mapper.selectById(id);
        if(entityPO==null) {
            throw new ServiceException(CoupousExceptionEnum.TICKET_BATCH_MERCHANT_GETONE_NULL);
        }
        return entityPO;
    }

    @Override
    public PageInfo<TicketBatchMerchantListPO> selectPage(PageParam pageParam) {
        return this.page(pageParam);
    }


    @Override
    public List<TicketBatchMerchantListPO> getList(TicketBatchMerchantListPO ticketBatchMerchantListPO) {
        return this.list(ticketBatchMerchantListPO);
    }
}
